if not menu then menu = {} end

if not menu.profit then


dofile (getScriptPath() .. "\\..\\lib\\lib.lua")

menu.profit = {}


processor:AddTimer(function()
	if menu.chart.instrument
		and menu.chart.changed.selected
	then
		window:SetCell(menu.portfolio.row, 3,
			string.format("%.0f-%s",
				lib:GetLotSize(menu.chart.instrument),
				lib:FormatPrice(menu.chart.instrument.min_price_step, menu.chart.instrument)
			)
		)
	end
end)


processor:AddTimer(function()
	if menu.chart.instrument
		and menu.label.prices.sev
		and menu.label.price.lm
		and menu.label.price.sl
		and (menu.label.changed.lm or menu.label.changed.sl)
		and menu.label.Create
	then
		local price
		
		if menu.label.price.lm < menu.label.price.sl then	-- short
			price = lib:NormalizePrice(menu.label.price.lm * (1 - menu.portfolio.commission), menu.chart.instrument, false)
		else												-- long
			price = lib:NormalizePrice(menu.label.price.lm * (1 + menu.portfolio.commission), menu.chart.instrument, true)
		end
		
		if price ~= menu.label.price.sev then
			menu.label:Create("sev", price)
		end
	end
end)


processor:AddTimer(function()
	if menu.chart.instrument
		and menu.label.prices.tev
		and (menu.label.changed.lm
			or menu.label.changed.sl
		)
		and menu.label.price.lm
		and menu.label.price.sl
		and menu.label.Create
	then
		local p = 2 * menu.label.price.lm - menu.label.price.sl
		
		if p > menu.label.price.lm then			-- long
			p = lib:NormalizePrice(p + menu.portfolio.commission * p, menu.chart.instrument, true)
		else									-- short
			p = lib:NormalizePrice(p - menu.portfolio.commission * menu.label.price.sl, menu.chart.instrument, false)
		end
		
		if p ~= menu.label.price.tev then
			menu.label:Create("tev", p)
		end
	end
end)


processor:AddTimer(function()
	if menu.chart.instrument
		and (menu.label.changed.lm
			or menu.label.changed.sl)
	then
		if menu.label.price.lm and menu.label.price.sl then
			menu.profit.sl = math.abs(menu.label.price.lm - menu.label.price.sl)
							/ math.min(menu.label.price.lm, menu.label.price.sl)
			window:SetCell(menu.label.show.sl.row, 3,
				string.format("%.2f%% [EVEN]", menu.profit.sl * 100)
			)
		else
			window:SetCell(menu.label.show.sl.row, 3, "")
		end
	end
end)


processor:AddTimer(function()
	if menu.chart.instrument
		and (menu.label.changed.lm
			or menu.label.changed.tp
			)
	then
		if menu.label.price.lm and menu.label.price.tp then
			menu.profit.tp = math.abs(menu.label.price.lm - menu.label.price.tp)
							/ math.min(menu.label.price.lm, menu.label.price.tp)
			window:SetCell(menu.label.show.tp.row, 3,
				string.format("%.2f%% %.1fx", menu.profit.tp * 100, (menu.profit.tp - menu.portfolio.commission) / menu.profit.sl)
			)
		else
			window:SetCell(menu.label.show.tp.row, 3, "")
		end
	end
end)


end	-- of file
